﻿using System.Collections.Generic;
using System.Linq;
using MySSH.IDAL;
using NHibernate;
using NHibernate.Criterion;

namespace MySSH.IBLL
{
    /// <summary>
    /// BLL接口层基类
    ///     约束BLL层必须有以下属性或方法
    /// </summary>
    /// <typeparam name="T">泛型约束T，必须是class类型或它的派生类和无参的构造函数</typeparam>
    public partial interface IBLLBase<T> where T : class, new()
    {

        /// <summary>
        /// 获取全部
        /// </summary>
        /// <returns></returns>
        IList<T> GetListAll();
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键</param>
        void Delete(object id);
        /// <summary>
        /// 根据主键获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T Get(object id);
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        T Save(T entity);
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity"></param>
        void Update(T entity);
        /// <summary>
        /// 保存或者更新
        /// </summary>
        /// <param name="entity"></param>
        void SaveOrUpdate(T entity);

        /// <summary>
        /// 获取Linq查询接口
        ///     默认启用查询缓存
        ///     强制刷新缓存：CacheMode(CacheMode.Refresh)
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetQueryByLinq();

        /// <summary>
        /// 获取HQL查询接口
        ///     默认启用查询缓存
        ///     如需取消，SetCacheable(false)
        /// </summary>
        /// <param name="queryString">HQL查询语句</param>
        /// <returns></returns>
        IQuery GetQueryByHQL(string queryString);

        /// <summary>
        /// 获取NHB标准查询数据访问接口
        ///     默认启用查询缓存
        ///     如需取消，SetCacheable(false)
        /// </summary>
        /// <returns></returns>
        ICriteria GetQueryByCriteria();

        /// <summary>
        /// 获取原生态SQL查询接口
        ///     推荐使用GetLinqQuery方法
        /// </summary>
        /// <param name="queryString">原生态SQL查询语句</param>
        /// <returns></returns>
        ISQLQuery GetQueryBySQL(string queryString);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="start">跳过序列中指定数量的元素</param>
        /// <param name="limit">从序列的开头返回指定数量的连续元素</param>
        /// <param name="sort">排序字段</param>
        /// <param name="dir">排序方式</param>
        /// <param name="totalCount">总行数</param>
        /// <param name="criterion">标准NHB查询参数</param>
        /// <returns></returns>
        IList<T> GetListByPage(int start, int limit, string sort, string dir, out int totalCount, List<ICriterion> criterion);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="start">跳过序列中指定数量的元素</param>
        /// <param name="limit">从序列的开头返回指定数量的连续元素</param>
        /// <param name="sort">排序字段</param>
        /// <param name="dir">排序方式</param>
        /// <param name="totalCount">总行数</param>
        /// <param name="isPage">是否执行分页</param>
        /// <param name="criterion">标准NHB查询参数</param>
        /// <returns></returns>
        IList<T> GetListByPage(int start, int limit, string sort, string dir, out int totalCount, bool isPage, List<ICriterion> criterion);


    }
}
